home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / doc / SetResult.3 < prev    next >
Text File  |  1993-01-31  |  6KB  |  164 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/SetResult.3,v 1.9 93/01/31 15:35:38 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .so man.macros
  13. .HS Tcl_SetResult tcl
  14. .BS
  15. .SH NAME
  16. Tcl_SetResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result string
  17. .SH SYNOPSIS
  18. .nf
  19. \fB#include <tcl.h>\fR
  20. .sp
  21. .VS
  22. \fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR)
  23. .VE
  24. .sp
  25. \fBTcl_AppendResult(\fIinterp, string, string, ... , \fB(char *) NULL\fR)
  26. .sp
  27. .VS
  28. \fBTcl_AppendElement\fR(\fIinterp, string, noSep\fR)
  29. .sp
  30. \fBTcl_ResetResult\fR(\fIinterp\fR)
  31. .sp
  32. \fBTcl_FreeResult\fR(\fIinterp\fR)
  33. .VE
  34. .SH ARGUMENTS
  35. .AS Tcl_FreeProc freeProc
  36. .AP Tcl_Interp *interp out
  37. Interpreter whose result is to be modified.
  38. .AP char *string in
  39. String value to become result for \fIinterp\fR or to be
  40. appended to existing result.
  41. .AP Tcl_FreeProc freeProc in
  42. .VS
  43. Address of procedure to call to release storage at
  44. \fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
  45. \fBTCL_VOLATILE\fR.
  46. .AP int noSep in
  47. If non-zero then don't output a space character before this element,
  48. even if the element isn't the first thing in the result string.
  49. .VE
  50. .BE
  51.  
  52. .SH DESCRIPTION
  53. .PP
  54. The procedures described here are utilities for setting the
  55. result/error string in a Tcl interpreter.
  56. .PP
  57. \fBTcl_SetResult\fR
  58. arranges for \fIstring\fR to be the return string for the current Tcl
  59. command in \fIinterp\fR, replacing any existing result.
  60. .VS
  61. If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fR
  62. refers to an area of static storage that is guaranteed not to be
  63. modified until at least the next call to \fBTcl_Eval\fR.
  64. If \fIfreeProc\fR
  65. is \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a call
  66. to \fBmalloc()\fR and is now the property of the Tcl system.
  67. \fBTcl_SetResult\fR will arrange for the string's storage to be
  68. released by calling \fBfree()\fR when it is no longer needed.
  69. If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fR
  70. points to an area of memory that is likely to be overwritten when
  71. \fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
  72. In this case \fBTcl_SetResult\fR will make a copy of the string in
  73. dynamically allocated storage and arrange for the copy to be the
  74. return string for the current Tcl command.
  75. .PP
  76. If \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,
  77. \fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
  78. of a procedure that Tcl should call to free the string.
  79. This allows applications to use non-standard storage allocators.
  80. When Tcl no longer needs the storage for the string, it will
  81. call \fIfreeProc\fR.  \fIFreeProc\fR should have arguments and
  82. result that match the type \fBTcl_FreeProc\fR:
  83. .nf
  84. .RS
  85.  
  86. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  87.  
  88. .RE
  89. .fi
  90. When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
  91. the value of \fIstring\fR passed to \fBTcl_SetResult\fR.
  92. .VE
  93. .PP
  94. If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
  95. and \fBTcl_SetResult\fR
  96. re-initializes \fIinterp\fR's result to point to the pre-allocated result
  97. area, with an empty string in the result area.
  98. .PP
  99. .VS
  100. If \fBTcl_SetResult\fR is called at a time when \fIinterp\fR holds a
  101. result, \fBTcl_SetResult\fR does whatever is necessary to dispose
  102. of the old result (see the \fBTcl_Interp\fR manual entry for details
  103. on this).
  104. .VE
  105. .PP
  106. \fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
  107. It takes each of its \fIstring\fR arguments and appends them in order
  108. to the current result associated with \fIinterp\fR.
  109. .VS
  110. If the result is in its initialized empty state (e.g. a command procedure
  111. was just invoked or \fBTcl_ResetResult\fR was just called),
  112. then \fBTcl_AppendResult\fR sets the result to the concatenation of
  113. its \fIstring\fR arguments.
  114. .VE
  115. \fBTcl_AppendResult\fR may be called repeatedly as additional pieces
  116. of the result are produced.
  117. \fBTcl_AppendResult\fR takes care of all the
  118. storage management issues associated with managing \fIinterp\fR's
  119. result, such as allocating a larger result area if necessary.
  120. Any number of \fIstring\fR arguments may be passed in a single
  121. call;  the last argument in the list must be a NULL pointer.
  122. .PP
  123. \fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
  124. .VS
  125. that it allows results to be built up in pieces.
  126. However, \fBTcl_AppendElement\fR takes only a single \fIstring\fR
  127. argument and it appends that argument to the current result
  128. as a proper Tcl list element.
  129. \fBTcl_AppendElement\fR adds backslashes or braces if necessary
  130. to ensure that \fIinterp\fR's result can be parsed as a list and that
  131. \fIstring\fR will be extracted as a single element.
  132. Under normal conditions, \fBTcl_AppendElement\fR will add a space
  133. character to \fIinterp\fR's result just before adding the new
  134. list element, so that the list elements in the result are properly
  135. separated.
  136. However, if \fIinterp\fR's result is empty when \fBTcl_AppendElement\fR
  137. is called, or if the \fInoSep\fR argument is 1, then no space
  138. is added.
  139. .PP
  140. \fBTcl_ResetResult\fR clears the result for \fIinterp\fR,
  141. freeing the memory associated with it if the current result was
  142. dynamically allocated.
  143. It leaves the result in its normal initialized state with
  144. \fIinterp->result\fR pointing to a static buffer containing
  145. \fBTCL_RESULT_SIZE\fR characters, of which the first character
  146. is zero.
  147. \fBTcl_ResetResult\fR also clears the error state managed by
  148. \fBTcl_AddErrorInfo\fR and \fBTcl_SetErrorCode\fR.
  149. .PP
  150. \fBTcl_FreeResult\fR is a macro that performs part of the work
  151. of \fBTcl_ResetResult\fR.
  152. It frees up the memory associated with \fIinterp\fR's result
  153. and sets \fIinterp->freeProc\fR to zero, but it doesn't
  154. change \fIinterp->result\fR or clear error state.
  155. \fBTcl_FreeResult\fR is most commonly used when a procedure
  156. is about to replace one result value with another.
  157. .VE
  158.  
  159. .SH "SEE ALSO"
  160. Tcl_AddErrorInfo, Tcl_SetErrorCode, Tcl_Interp
  161.  
  162. .SH KEYWORDS
  163. append, command, element, list, result, return value, interpreter
  164.